/*
 * Vlabs Biological Web Elemments
 *
 * Copyright (c) 2009 Victor de la Torre (vdelatorre@cnio.es)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * 
 * http://code.google.com/p/bwe/ 
 *
 */
 
 (function($) {

 	$.bwe.sequence = $.bwe.sequence || {}; //Add the 'sequence' scope
 	
 	$.bwe.sequence.instance = function(container,label,onclick,functionLabel){
		
		$.bwe.buidElement(container,label,'$.bwe.sequence.'+onclick,functionLabel);
	}
	
	$.bwe.sequence.getProteinSequence = function(id,label){
		
		var serv = new UniprotDas();
		
		if ($.bwe.animate(id,445,180)){
		
			serv.getSequence(function(data){
								
				sequence = data.DASSEQUENCE.SEQUENCE;
				
				sequenceDiv = jQuery('<div></div>');
				$.bwe.sequence.paintSequence(sequenceDiv,sequence);
				

				$("#loading"+id).remove();
				$("#"+id).append(sequenceDiv);
					
			},label);
		}
	
	}
	
	
	$.bwe.sequence.paintSequence =  function(div,sequence){
	
		length	 = sequence.length;
			
		aaDiv 		= jQuery('<div style="text-align:left;padding:10px;"></div>');				
		resumeDiv 	= jQuery('<div style="text-align:left;padding-left:10px;"></div>');

		var shortS =  new Array(); 
		c = 1;
		for(i=0;i<=length;i+=10){
		
			shortS[i+10] = sequence.substring(i,i+9);
			aaDiv.append('<span class="bwe-textCourier12">'+shortS[i+10]+'</span>');
			if (c%6 == 0 && c != 1)
				aaDiv.append('<br>');
			else
				aaDiv.append('&nbsp');
			c++		
		}
		resumeDiv.append('<span>Length:</span> <span class="bwe-h11-blue">'+length+'</span>');
		
		div.append(aaDiv);
		div.append(resumeDiv);
		
	}
	
 })(jQuery);  